﻿
/**
* 命名空间: Game.TDBehaviorTree
*
* 功 能： N/A
* 类 名： INode  节点基类
*
* Ver 变更日期 负责人 变更内容
* ───────────────────────────────────
* V0.01 2019/12/11 14:46:35  
*/
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Game.TDBehaviorTree
{

    [JsonObject(MemberSerialization.OptIn)]
    /// <summary>
    /// 节点基类
    /// </summary>
    public  class NodeBase
    {
        [JsonProperty("nodeType")]
        public NodeType m_NodeType;

        [JsonProperty("nodeLeafType")]
        public int m_LeafType;

        [JsonProperty("nodeIndex")]
        protected int m_NodeIndex;

       
        protected UnityEngine.GameObject m_Agent;

        private Action m_NodeCompleteAction;

        public NodeBase() { }
        public NodeBase(NodeType _type)
        {
            m_NodeType = _type;
        }

        /// <summary>
        /// 具体节点执行
        /// </summary>
        /// <returns></returns>
        public virtual NodeResultType Execute() { return NodeResultType.Success; }

#if UNITY_EDITOR

        public virtual void Draw(UnityEngine.Rect m_Rect, UnityEngine.GUIStyle style, NodeValue _value)
        {
           
        }

        public string GetNodeTypeDraw()
        {
            StringBuilder buildStr=new StringBuilder();
            buildStr.Append(EnumberHelper.GetDescription(m_NodeType) + ":");
            if (m_NodeType == NodeType.Action)
            {
                buildStr.Append(EnumberHelper.GetDescription((ActionNodeType)m_LeafType));
            }
            return buildStr.ToString();
        }


        public virtual void DeRializable(NodeValue _value)
        {

        }
#endif


        /// <summary>
        /// 节点下标
        /// </summary>
        /// 

        public int NodeIndex
        {
            get
            {
                return m_NodeIndex;
            }
            set
            {
                m_NodeIndex = value;
            }
        }

      
         
        public UnityEngine.GameObject Agent
        {
            get
            {
                return m_Agent;
            }
            set
            {
               
                if (m_NodeType==NodeType.Parallel || m_NodeType==NodeType.Random || m_NodeType==NodeType.Select || m_NodeType==NodeType.Sequence)
                {
                    foreach (var item in (this as NodeCombine).m_childNodes)
                    {
                        item.Agent = value;
                    }
                }
                m_Agent = value;
            }
        }

        public Action NodeCompleteAction
        {
            get
            {
                return m_NodeCompleteAction;
            }
            set
            {
                m_NodeCompleteAction = value;
            }
        }
    }
}

